package com.example.login_register;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        Button btn_login = findViewById(R.id.btn_login);
        TextView tv_zc = findViewById(R.id.tv_zc);
        EditText et_account = findViewById(R.id.et_account);
        EditText et_password = findViewById(R.id.et_password);

        tv_zc.setOnClickListener(v ->
        {
            Intent intent = new Intent(LoginActivity.this,registerActivity.class);
            startActivity(intent);
        });

        btn_login.setOnClickListener(v ->
        {
            Intent intent = new Intent(LoginActivity.this,LogonActivity.class);
            intent.putExtra("account",et_account.getText().toString().trim());
            intent.putExtra("password",et_password.getText().toString().trim());
            startActivityIfNeeded(intent, 1);

        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1 && resultCode ==2)
        {
            Toast.makeText(this, data.getStringExtra("main_data"),Toast.LENGTH_SHORT).show();
        }
    }
}